<?php
/*
 * ebiz front
 *
 * CategoryFirstViewL1V2
 *
 * @author xiaoyuemian
 * 
 */

require_once '../app/util/TemplateReplaceUtil.php';
require_once '../app/util/TagUtil.php';
require_once '../app/views/HeaderView.php';
require_once '../app/views/FooterView.php';
require_once '../app/util/CommonUtil.php';
require_once '../app/services/CategoryService.php';

define('PRODUCTS_LIST_L1V2_PAGE_SIZE', 12);
define('PRODUCTS_LIST_L1V2_ROW_SIZE', 4);
define('MAKETING_PRICE', '市场价');
define('SALES_PRICE', '米米价');

class CategoryFirstViewL1V2 extends BaseView{

//    public $leftMenus = array();
//    public $saleProductsGrop = array();
//    public $otherProductsGrop1 = array();
//    public $otherProductsGrop2 = array();
    private $params = array();
    
    private $categoryService;
    public $m_category;
    public $m_products;
    public $m_pager;
    public $m_sortby;
    public $m_navigation;
    public $m_metadatas;
    public $m_filter;
        
    public function __construct(){
    	parent::__construct();
    	$this->categoryService = new CategoryService();
    }

	public function getCategoryFirstViewPage($params){
		$this->params = $params;
        $arr_navsetting = array(
            array('url'=>'','text'=>$this->leftMenus['fullname'])
        );		//xiaoyuemian: leftMenus在哪儿定义的?
        $this->setPageTitle($this->params['category']['short_name']);
        //xiaoyuemian: 这俩外面加过了啊，可以不加不？
        $this->addCSS('productlist.css');
        $this->addJs('class1.js');
        //load templete
        $scpPath = "layout/category/" . $this->params['category']['url_title'] .".scp";
        $dataScp = TemplateReplaceUtil::getXmlTemplate($scpPath);
        if(empty($dataScp)){
        	HttpUtil::renderError();
        }
        //
        $header = '';
        $str_result = $header
                    . $this->getNavigation($arr_navsetting)
    		        . "<div class='p1_main'>"
    		        . $this->getContentLeftBlock($dataScp->left)
    		        . $this->getContentRigthBlock($dataScp->right)
    		        . "</div>";
    		        
        return $this->getHtmlPage($str_result);
	}
	
	public function getCategoryFirstViewPageV2()
	{
		$this->params['category'] = $this->m_category;
        $arr_navsetting = array();
        $arr_categoryies = $this->m_navigation;
		while($arr_category=array_pop($arr_categoryies)){
            if(!empty($arr_categoryies)){
                //if(empty($arr_category['parent_id']))
                    $arr_navsetting[] = array('url'=>'/c/index/'.$arr_category['url_title'], 'text'=>$arr_category['short_name']);
                //else
                //    $arr_navsetting[] = array('url'=>'/c/search/'.$arr_category['id'], 'text'=>$arr_category['short_name']);
            }else{
                $arr_navsetting[] = array('text'=>$arr_category['short_name']);
            }
        }
        
        $this->setPageTitle($this->m_category['short_name']);
        //xiaoyuemian: 这俩外面加过了啊，可以不加不？
        $this->addCSS('productListL1V2.css');
        $this->addJs('productListL1V2.js');
        //load templete
        //xiaoyuemian:attention!!! url_title后加'_test'，使用测试版模板
        //echo "viewcount = ".count($arr_naviation);
        //echo "nav = ".$arr_naviation[count($arr_naviation) - 1]['url_title'];
        $scpPath = "layout/category/" . $this->m_navigation[count($this->m_navigation) - 1]['url_title']."_test".".scp";
        $dataScp = TemplateReplaceUtil::getXmlTemplate($scpPath);
        if(empty($dataScp)){
        	HttpUtil::renderError();
        }
        
        $header = '';
        $str_result = $header
                    . $this->getParentsNavigation($arr_navsetting)
    		        . "<div id='c_body'>"
    		        . $this->getContentLeftBlockV2($dataScp->left)
//    		        . $this->getContentRigthBlockV2($arr_categoryId, $arr_metadatas, $arr_products, $arr_pager, $arr_sortby, $arr_filter, $arr_naviation)
    		        . $this->getContentRigthBlockV2()
    		        . "</div>";
    		        
        return $this->getHtmlPage($str_result);
	}
	
	public function getNavigation(){
		$str = '<div class="p1_loc"><span><a href="/">'. WEBSITEINDEXPAGETXT .'</a></span>><span><a href="#">'.$this->params['category']['short_name'].'</a></span></div>';
	    return $str;
	}
	
	public function getParentsNavigation($arr_param){
        $str_result = '<div class="p1_loc">'
                    . "<span><a href='/'>" . WEBSITEINDEXPAGETXT . "</a></span>";
        if (empty($arr_param))
            return $str_result . "</div>";
        /*switch(count($arr_param))
        {
        	case 0:
        		return $str_result . "</div>";
        		break;
        	case 1:
        		$str_result.= '><span><a href="#">' . $arr_param[0]['text'].'</a></span>';
        		return $str_result . '</div>';
        		break;
        	default:
        		$str_result.= "><span><a href='{$arr_param[0]['url']}'>{$arr_param[0]['text']}</a></span>";
        		$str_result.= '><span><a href="#">' . $arr_param[count($arr_param) - 1]['text'].'</a></span>';
        		return $str_result . '</div>';
        }*/
        foreach ($arr_param as $arr_array){
            if (empty($arr_array['url']))
                $str_result.= '><span><a href="#">' . $arr_array['text'].'</a></span>';
            else
                $str_result.= "><span><a href='{$arr_array['url']}'>{$arr_array['text']}</a></span>";
        }
        return $str_result . '</div>';
    }
	

	public function getLeftTopBlock($left){
		$str = '<div class="p1_lefttop"><img src="'. ConfigConstants::getTImagePath() .'/p1_lefttopbg.gif" alt="" /></div>';
		return $str;
	}
	
	public function getContentLeftBlock($leftXml){
        $leftHtml = "<div class='p1_left'>" . $this->getCategoryVerticlMenu($leftXml) . '</div>';
        return $leftHtml;
	}
	
	public function getContentLeftBlockV2($leftXml){
        $leftHtml = "<div id='p1_left'>" . $this->getCategoryVerticlMenuV2($leftXml) . '</div>';
        return $leftHtml;
	}

	/**
	 * @return string
	 */
	public function getCategoryVerticlMenu($leftXml){
		if(empty($leftXml) || empty($leftXml->item)){
			return "";
		}
		$items = $leftXml->item;
		$html= '<div class="p1_lefttop"><img src="'. ConfigConstants::getTImagePath() .'/p1_lefttopbg.gif" alt="" /></div>'
		       . "<div class='p1_leftcenter'>"
               . '<div class="p1_left01">
				       <h5>'. $this->params['category']['short_name'] .'</h5>
				       <div class="p1_left02top"></div>
				       <div class="p1_left03">';
               

         $i = 1;
		 foreach($items as $item){
		 	$html .=  '<ul>';   
		 	$html .=  '<li id="p1_li_'.$i.'" class="p1_left03_li">';
		 	$html .=  '<a href="#" class="menu2" id="'.$i.'" onclick="javascript:changeDivStatus(\''.$i.'\');">'.$item->title.'</a>';
		 	$html .=  '<ul id="p1_ul_'.$i.'">';
		 	foreach($item->metadata as $metadata){
		 		$html .= '<li><a href="/c/search'.$metadata->key.'">'.$metadata->title.'</a></li>';
		 	}		 	 
		 	$html .=  '</ul>';
		 	$html .=  '</li>';
		 	$html .=  '</ul>';
		 	$i++;
		 }		         
		 $html	.=	    '</div>
				       <div class="p1_left02bottom"></div>
				 </div>'
		       . "</div>"
		        . '<div class="p1_leftbottom"><img src="'.ConfigConstants::getTImagePath().'/p1_leftbottombg.gif" alt="" />
		                <div style="margin-top:10px;">
		       			<script type="text/javascript">
							<!--
				            google_ad_client = "pub-1231013902088237";
				            /* 200x200, 创建于 09-11-9 */
				            google_ad_slot = "0725208146";
				            google_ad_width = 200;
				            google_ad_height = 200;
				            //-->
			            </script>
			            <script type="text/javascript" src=" http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
			            </div> 
		         </div>';
		       
		  return $html;     
	}
	
	/**
	 * @return string
	 */
	public function getCategoryVerticlMenuV2($leftXml){
		if(empty($leftXml) || empty($leftXml->item)){
			return "";
		}
		$items = $leftXml->item;
		$html = '<div class="cb_top"></div>'
		        .'<div class="cb_center">'
		        //.'<div class="c_title"><img src="image/10-31_08.jpg" alt="" /></div>'
		            .'<div class="c_body">
		                  <div class="c_t"></div>
		                  <div class="c_c">';
		                      /*<div class="list_all">'
		                      . $this->params['category']['short_name']
		                      .'</div>';*/
		
        foreach($items as $item){
		 	$html .=  '<div class="list_title">
		 	                <h3><span><img src="'. ConfigConstants::getTImagePath() .'/p1_leftMenuMinus.gif" alt="" /></span>'
		 	          .'<a href="/c/index'.$item->key.'">'
		 	          . $item->title. '</a></h3>';
		 	foreach($item->metadata as $metadata){
		 		if (strrpos($metadata->key, "/") > 0)
		 			$html .= '<p><a href="/c/search'.$metadata->key.'">'.$metadata->title.'</a></p>';
		 		else
			 		$html .= '<p><a href="/c/index'.$metadata->key.'">'.$metadata->title.'</a></p>';
		 	}		 	 
		 	$html .=  '</div>';
		 }	
		 $html .= '</div>
		          <div class="c_b"></div>
		          </div></div>'
		          //.'<div class="cb_bottom"></div>';	//div c_body, cb_center end
		           . '<div class="cb_bottom">
		              </div><div style="margin-top:10px;">
		       			<script type="text/javascript">
							<!--
				            google_ad_client = "pub-1231013902088237";
				            /* 200x200, 创建于 09-11-9 */
				            google_ad_slot = "0725208146";
				            google_ad_width = 200;
				            google_ad_height = 200;
				            //-->
			            </script>
			            <script type="text/javascript" src=" http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
			            </div>';
		 
		       
		  return $html;     
	}
	
	/**
	 * Get right block
	 *
	 * @param array $arr_param
	 * @return string
	 */
	public function getContentRigthBlock($rightXml){

		return "<div class='p1_right'>"
		       .$this->getRightTopBlock($rightXml->top)
		       .$this->getRightCenterBlock($rightXml->center)
		       .$this->getRightBottomBlock($rightXml->bottom)
               . '</div>';
	}
	
	//xiaoyuemian: Black => Block, 2009-11-08, 18:47
	public function getRightTopBlock($topXml){
	     if(empty($topXml) || empty($topXml->item)){
	          return "";
	     } 
	     $html = '<div class="p1_right01">';
	     $html .= '<div class="p1_right01top"></div>';
	     $html .= '<div class="p1_right01title">';
	     $html .= '<div class="p1_right01title_01">';
	     $html .= '<img width="86" height="22" alt="" src="'. ConfigConstants::getTImagePath() .'/category/xscx.gif"/>';
	     $html .= '</div>';
	     $html .= '</div>';
	     $html .= '<div class="p1_right01_1">';
	     //xiaoyuemian: 这段html该在foreach里吧。。这要是不小心top里有多个item或者不限时促销了，显示会有问题吧？没有上面的标题(title)了
         foreach($topXml->item as $item){
         	 $imagePath = ConfigConstants::getTImagePath() . "/category/" . $item->image;
         	 $type = $item->type;
         	 $productItems = $this->categoryService->getSpecialProductByType($type);
             $i = 1;
             foreach($productItems as $productItem){

             	if($i <= 9){
             		$urlTitle = $productItem['url_title'];
             		$title = CommonUtil::cut_str($productItem['title'],23);
             		$marketPrice = $productItem['marketing_price'];
             		$salePrice = $productItem['sale_price'];
             		$ifolder = $productItem['ifolder'];
             		$iname = $productItem['iname'];
             		if(empty($iname)){
             			$productImage250 = ConfigConstants::getDefaultProductImagePath("250");
             			$productImage100 = ConfigConstants::getDefaultProductImagePath("100");
             		}else{
             			$productImage250 = ConfigConstants::getProductImagePath($ifolder,$iname,"250");
             			$productImage100 = ConfigConstants::getProductImagePath($ifolder,$iname,"100");
             		}
              		if($i == 1){
             			$html .= '<div class="p1_right01_2">';
             			$html .= '<a href="/p/'. urlencode($urlTitle) .'/'. $productItem['id'] .'">';
             			$html .= '<img src="'.$productImage250.'" alt="" />';
             			$html .= '</a>';
             			$html .= '<div class="p1_right01_2p">';
             			$html .= '<div class="p1_right01_2p1">';
             			$html .= '<p>'.$title.'</p>';
             			$html .= '<p>米米价|<span class="p1_mprice">￥' . $marketPrice . '</span></p>';
             			$html .= '<p>促销价|<span class="p1_mprice1">￥' . $salePrice . '</span></p>';
             			$html .= '</div>'; 
             			$html .= '</div>'; 
             			$html .= '</div>'; 
             		}else{
                        $html .= '<div class="p1_right01_3" style="height:auto;">';
                        $html .= '<a href="/p/'. urlencode($urlTitle) .'/'. $productItem['id'] .'">';
                        $html .= '<img src="'.$productImage100.'" alt="" />';
                        $html .= '</a>';
                        $html .= '<div class="p1_right01_3p p1_right01_3p'.$i.'" style="height:auto">';
                        $html .= '<div style="height:60px;padding-left:25px;dispaly:block;word-break:break-all;width:80px;">'.$title.'</div>';
                        $html .= '<div>';
                        $html .= '<p>米米价|<span class="p1_mprice">￥' . $marketPrice . '</span></p>';
                        $html .= '<p>促销价|<span class="p1_mprice1">￥' . $salePrice . '</span></p>'; 
                        $html .= '</div>';
                        $html .= '</div>';                      
                        $html .= '</div>';
             		}
             	}
             	/* xiaoyuemian: else 呢？break?*/
             	$i++;
             }   
         }
        $html .= '</div>'; 
        $html .= '</div>'; 
        return $html;
	}
	
	public function getRightCenterBlock($centerXml){
	     if(empty($centerXml) || empty($centerXml->item)){
	            return "";
	     } 	     
	     $html = '';
	     foreach($centerXml->item as $item){
	          $imagePath = ConfigConstants::getTImagePath() . "/category/" . $item->image;
	          $type = $item->type;
	          $productItems = $this->categoryService->getSpecialProductByType($type);
	          if(empty($productItems)){
	          	 continue;
	          }
	          $html .= '<div class="p1_right02">';  
              $html .= '<div class="p1_right02title">';
              $html .= '<div class="p1_right02title_01">';
              $html .= '<img src="'.$imagePath.'" width="86" height="22" alt="" />';
              $html .= '</div>';     
              $html .= '</div>';
              $i = 1;
	          foreach($productItems as $productItem){
	          	  if($i <= 6){
		          	    $title = CommonUtil::cut_str($productItem['title'],25);
		          	    $urlTitle = $productItem['url_title'];
	                    $marketPrice = $productItem['marketing_price'];
	                    $salePrice = $productItem['sale_price'];
	                    $ifolder = $productItem['ifolder'];
	                    $iname = $productItem['iname'];
	                    if(empty($iname)){
	                        $productImage100 = ConfigConstants::getDefaultProductImagePath("100");
	                    }else{
	                        $productImage100 = ConfigConstants::getProductImagePath($ifolder,$iname,"100");
	                    }	      
	                    if($i == 1){
	                    	$html .= '<div class="p1_right02_01">';
	                    }else{
	                    	$html .= '<div class="p1_right02_01 p1_right02_02">';
	                    }    	  	
	                    $html .= '<a href="/p/'. urlencode($urlTitle) .'/'. $productItem['id'] .'">';
		                $html .= '<img src="'.$productImage100.'" alt="" />';
		                $html .= '</a>';
		                $html .= '<p style="height:60px;">'; 
		                $html .= $title;
		                $html .= '</p>'; 
		                $html .= '<p><span>￥'.$salePrice.'</span></p>';
		                $html .= '</div>';	          	  	
	          	  }
                  $i++;
	          } 
              $html .= '</div>'; 
	     }

	     return $html;	
	}

    public function getRightBottomBlock($bottomXml){
     if(empty($bottomXml) || empty($bottomXml->item)){
            return "";
     }    	
     $html = '<div class="p1_right03">
     <div class="p1_right03top"></div>
     <div class="p1_right03title"><img src="'.ConfigConstants::getTImagePath().'/p1_righttitleimg4.gif" width="147" height="19" alt="" /></div>
     <div class="p1_right03_1">';
     foreach($bottomXml->item as $item){
     	$html .= '<ul class="p1_right03_1ul">';
     	$html .= '<li class="seperator">'.$item->title.'</li>';
     	$i = 0;
     	foreach($item->metadata as $metadata){
     		if($i == 0){
     			$html .= '<li class="p1_right03li01" onclick="javascript:window.location=\'/c/search'.$metadata->key.'\';">'.$metadata->title.'</li>';
     		}else{
     			$html .= '<li class="p1_right03li" onclick="javascript:window.location=\'/c/search'.$metadata->key.'\';">'.$metadata->title.'</li>';
     		}
     		$i++;
     	}
     	$html .= '</ul>';
     }
     $html .= '</div>
     </div>';
    	
    	return $html;
    }

	/**
	 * Get right block, Version 2
	 * @desc Level 1 Version 2，页面右，显示某Category下全部商品
	 *
	 * @param array $arr_param
	 * @return string
	 */
	public function getContentRigthBlockV2(){
        /*if(is_null($arr_products))
            $arr_products = $this->products;
        if(is_null($arr_sortby))
            $arr_sort = $this->sort;
        if(is_null($arr_pager))
            $arr_pager = $this->pager;*/
        
        //搜索结果，$arr_pager['countrows']为结果数
        $str_result = "<div class='p1_right'>";
/*        $str_result = "<div id='searchResultBlock' class='p2_search'>"
               . "<div class='p2_title'><a name='searchresultplace'><img src='" . ConfigConstants::getTImagePath() . "/p2_searchbg.gif' /></a><p>" . sprintf(SEARCHRESULTNUMBERROWSTXT, "<span>{$arr_pager['countrows']}</span>") . '</p></div>';*/
        if(!empty($this->m_products)){
            $str_result.= $this->getFilterBlock()
                        . '<div id="RightBlockFreshContent">'
                        //. sprintf(SEARCHRESULTNUMBERROWSTXT, "<span>{$this->m_pager['countrows']}</span>")
                        . $this->getSearchResultTitle()                   
                        . $this->getSearchResultContent()
                        . '<div id="product_hr">
                               <div class="s_nav_b" style="margin-left:1px; width:756px;"></div>
                               <div class="s_nav_b" style="margin-left:2px; width:754px; background:#CBCBCB;"></div>    
                           </div></div>';
        }
        $str_result.= '</div>';
        return $str_result;
	}
	
	protected function getFilterBlock($arr_metadatas = array())
	{
		if(empty($arr_metadatas))
		    $arr_metadatas = $this->m_metadatas;
		    
		if(empty($arr_metadatas['品牌'])) //|| empty($arr_metadatas['prices'])
		    return '';
		
		return $this->getSortList($arr_metadatas);
	}

    /**
     * 获得筛选条件清单
     *
     * @return string
     */
    protected function getSortList($arr_metadatas = array()){
    	if(empty($arr_metadatas))
    	    $arr_metadatas = $this->m_metadatas;
        if (empty($arr_metadatas))
            return '';
            
        $str_result = "<form id='filterListForm'><div class=\"filter_box\">";
        foreach ($arr_metadatas as $str_mTitle => $arr_metadata) {
			//print_r($arr_metadata);exit;
			/**
			 * @desc 生成一行
			 */
        	$tmpMetadataId = $arr_metadata[0]['metadata_id'];
			$str_result.= '<div id="c_brand"><ul>';
			$str_result.= $this->getSortListOptions($arr_metadata, $tmpMetadataId);
			$str_result.= "</ul></div>";
			$str_result .= "<div id=\"c_brand_t\">$str_mTitle<input id='metadata_" 
			    . $tmpMetadataId 
			    . "' type='hidden' name='metadata[" 
			    . $tmpMetadataId . "]' /></div>";
		}
		$str_result .= "</div></form>";
        return $str_result;
    }

    /**
     * 列出一行筛选条件
     *
     * @param array $arr_options
     * @param int $int_parentid
     * @return string
     */
    protected function getSortListOptions($arr_options, $int_parentid) {
        $bool_selectOther = false;
        if (!empty($arr_options)&&!empty($this->filter)) {
            foreach ($arr_options as $arr_option) {
                if (array_key_exists('auto_metadata_'.$int_parentid,$this->filter) && in_array($arr_option['id'],$this->filter))
            	   $bool_selectOther = true;
            }
        }
        $str_result = "<li" . ($bool_selectOther ? '' : " class=\"style_2\"" ) . " parentid='{$int_parentid}' selfid='0'>" . SEARCHALLOPTIONSTXT . '</li>';
        if (!empty($arr_options)) {
            $int_number = 0;
            foreach ($arr_options as $arr_option) {
                $int_number++;
                if($int_number > 19)
                    break;
                if (!empty($this->filter) && array_key_exists('auto_metadata_'.$int_parentid,$this->filter) && in_array($arr_option['id'],$this->filter))
            	   $str_result.= "<li class=\"style_2\" parentid='{$int_parentid}' selfid='{$arr_option['id']}'>{$arr_option['title']}</li>";
                else
            	   $str_result.= "<li class=\"others_style\" parentid='{$int_parentid}' selfid='{$arr_option['id']}'>{$arr_option['title']}</li>";
            }
        }

        return $str_result;
    }
    
    public function getRightBlockProductsResult()
    {	    
    	return '<div id="RightBlockFreshContent">'
                        . $this->getSearchResultTitle()                   
                        . $this->getSearchResultContent()
                        . '<div id="product_hr">
                               <div class="s_nav_b" style="margin-left:1px; width:756px;"></div>
                               <div class="s_nav_b" style="margin-left:2px; width:754px; background:#CBCBCB;"></div>    
                           </div></div>';
    }
	
    /**
     * 结果集的排序选择部分
     *
     * @param array $arr_sort
     * @return string
     */
    protected function getSearchResultTitle($arr_sort = array(), $arr_pager = array()){
    	if(empty($arr_sort))
    	    $arr_sort = $this->m_sortby;
    	if(empty($arr_pager))
    	    $arr_pager = $this->m_pager;
    	    
    	$str_result = '<div id="p1_right">'
    	. '<div id="s_count">'.sprintf(SEARCHRESULTNUMBERROWSTXT, "<span>{$this->m_pager['countrows']}</span>")
    	. '</div>'
    	. '<div id="s_nav">
    	<div class="s_nav_b" style="margin-left:2px; width:754px; background:#CBCBCB;"></div>
        <div class="s_nav_b" style="margin-left:1px; width:756px;"></div>
        <div class="s_nav_t">
            <div class="right_nav">'
                . '<div class="left_name">'.SEARCHSORTBYTXT . '</div>'
                //. '<div class="right_nva_px">'
                . "<select onchange=\"if(event){\$('#sortby_created_select').val(0); formatFormData(1);}\" style='margin-top:5px;' id='sortby_price_select'>
                    <option value='0' " . (empty($arr_sort['price'])?"selected='selected'":'') . '>' . SEARCHSORTBYPRICEOPT . "</option>
                    <option value='1' " . ($arr_sort['price']>0?"selected='selected'":'') . '>' . SEARCHSORTBYPRICEOPT.SEARCHORDERASCOPT . "</option>
                    <option value='-1' " . ($arr_sort['price']<0?"selected='selected'":'') . '>' . SEARCHSORTBYPRICEOPT.SEARCHORDERDESCOPT . "</option>
                  </select>"
                . "<select onchange=\"if(event){\$('#sortby_price_select').val(0); formatFormData(1);}\" style='margin-top:5px;margin-left:5px;' id='sortby_created_select'>
                    <option value='0' " . (empty($arr_sort['created'])?"selected='selected'":'') . '>' . SEARCHSORTBYCREATEDOPT . "</option>
                    <option value='1' " . ($arr_sort['created']>0?"selected='selected'":'') . '>' . SEARCHSORTBYCREATEDOPT.SEARCHORDERASCOPT . "</option>
                    <option value='-1' " . ($arr_sort['created']<0?"selected='selected'":'') . '>' . SEARCHSORTBYCREATEDOPT.SEARCHORDERDESCOPT . "</option>
                  </select>"
                . '</div>';
           //</div>';
        $str_result .= '<div class="page_nav">';
        if($this->m_pager['nowpage'] > 1)
            $str_result .= '<p class="s_1"><a href="javascript:void(0);" '
                    . ' onclick="formatFormData('
                    . ($this->m_pager['nowpage'] - 1)
                    .')" >上一页</a></p>';
        $str_result .= '<p class="s_2">'
                    . $this->getPager($arr_pager)
                	.'</p>';
        if($this->m_pager['nowpage'] < Pager::GetCountPage($this->m_pager['countrows'], PRODUCTS_LIST_L1V2_PAGE_SIZE))
            $str_result .= '<p class="s_1"><a href="javascript:void(0);" '
                    . ' onclick="formatFormData('
                    . ($this->m_pager['nowpage'] + 1)
                    .')" >下一页</a></p>';
        $str_result .= '</div>
                    </div>
                </div>
                <div id="class_hr"></div>';
        
        return $str_result;
    }
	
    /**
     * 结果集的商品内容显示部分
     *
     * @param array $arr_products
     * @return string
     */
    protected function getSearchResultContent($arr_products = array(), $arr_pager = array()){
    	if(empty($arr_products))
    	    $arr_products = $this->m_products;
    	    
    	if(empty($arr_pager))
    	    $arr_pager = $this->m_pager;
    	    
        $str_result = '<div id="class_product">';
        $int_productNumber = 0;
        if (!empty($arr_products)) {
            foreach ($arr_products as $arr_product){
                $str_result.= $this->getSearchResultProduct($arr_product);
                $int_productNumber++;
            }
            if (($index = $int_productNumber % PRODUCTS_LIST_L1V2_ROW_SIZE) != 0) {
            	for(;$index < PRODUCTS_LIST_L1V2_ROW_SIZE;$index++) {
            		$str_result .= $this->getSearchResultEmptyProduct();
            	}
            }
        }
        $str_result .= $this->getSearchResultFooter($arr_pager);
        $str_result.= '</div>';
        return $str_result;
    }

    /**
     * 显示一个商品
     *
     * @param array $arr_product
     * @return string
     */
    protected function getSearchResultProduct($arr_product){
        return '<div class="pro_list">'
    	       .'<a href="/p/'. urlencode($arr_product['url_title']).'">'
		       .'<img src="'.(empty($arr_product['image_name']) ? ConfigConstants::getDefaultProductImagePath('160'):ConfigConstants::getProductImagePath($arr_product['image_folder'],$arr_product['image_name'],'160'))
		       .'" alt="" />'
		       .'</a>'
		       .'<p class="title_1">'
		       .$arr_product['title']
		       .'</p>'
		       .'<p class="title_2">'.SEARCHMARKETINGPRICETXT.'￥'.$arr_product['marketing_price'].'</p>'	//市场价
		       .'<p class="title_2">'.AKIMIMIPRICETXT.'<span><b>￥'.$arr_product['sale_price'].'</b></span></p>'			//米米价
               . '</div>';
    }
    
    protected function getSearchResultEmptyProduct(){
        return '<div class="pro_list">'
               . '</div>';
    }

    /**
     * 结果集的分页条
     *
     * @param array $arr_pager
     * @return string
     */
    protected function getPager($arr_pager){
        require_once '../app/util/PagerNew.php';
        $pager = new PagerNew(null, 'pageNumber');
        $pager->curNumStyle = '';
        $pager->numLinkStyle = '';
        $pager->spaceElement = "<a class='p_dd'>...</a>";
        $pager->pagerCssFront = '';
        $pager->pagerCssBack = '';
        $pager->setJavascriptFunction('formatFormData');
        return $pager->paginate($arr_pager['nowpage'],$arr_pager['countrows'],'/a/categoryindex/'.$this->params['category']['url_title'].'/', PRODUCTS_LIST_L1V2_PAGE_SIZE);
    }

    /**
     * 页面底部，结果集的分页条
     *
     * @param array $arr_pager
     * @return string
     */
    protected function getSearchResultFooter($arr_pager){
    	$str_result = "<div class=\"bottom_page\">";
//    	$str_result = '';
    	if($this->m_pager['nowpage'] > 1)
        	$str_result .= "<p class='s_1'><a href='javascript:void(0);' onclick=\"formatFormData("
                    . ($this->m_pager['nowpage'] - 1)
                    .")\" >" . "上一页" . "</a></p>";
        $str_result .= "<p class='s_2'>".$this->getPager($arr_pager)."</p>";
        $totalPage = Pager::GetCountPage($this->m_pager['countrows'], PRODUCTS_LIST_L1V2_PAGE_SIZE);
        if($this->m_pager['nowpage'] < $totalPage)
            $str_result .= "<p class='s_1'><a href='javascript:void(0);' style='margin-left:5px;' onclick=\"formatFormData("
                    . ($this->m_pager['nowpage'] + 1)
                    .")\" >" . "下一页" . "</a></p>";
        $str_result .= "<p class='s_3'>共{$totalPage}页，当前第{$this->m_pager['nowpage']}页</p>";
        if($totalPage > 1)
            $str_result .= '<p class="s_4"><input type="text" id="pageNumberToJump" class="input_text"></p>'
                        . '<input type="hidden" id="totalPage" value="'. $totalPage .'">'
                        . "<p class='s_5'><a href='javascript:void(0);' onclick=\"jampToCertanPage()\""
                        ." >" . "跳转" . "</a></p>";
        $str_result .= '</div>';
        
        return $str_result;
     }
}
